package com.qianfeng.listviewduobuju;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
    private ListView mListView;
    private MyAdapter mAdapter;
    private List<IItem> mList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mListView= (ListView) findViewById(R.id.listview);
        mAdapter=new MyAdapter(this);
        mListView.setAdapter(mAdapter);

        //数据
        initdata();

    }

    private void initdata() {
        Random random=new Random();
        mList=new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            int type=random.nextInt(3);
            switch (type){
                case 0:
                    Item0 item0=new Item0();
                    item0.setInfo("布局一,数据"+i);
                    mList.add(item0);
                    break;
                case 1:
                    Item1 item1=new Item1();
                    item1.setInfo1("布局2,数据"+i);
                    item1.setInfo2("布局2,数据"+i);
                    mList.add(item1);

                    break;
                case 2:

                    Item2 item2=new Item2();
                    item2.setInfo1("布局3,数据"+i);
                    item2.setInfo2("布局3,数据"+i);
                    item2.setInfo3("布局3,数据"+i);
                    mList.add(item2);
                    break;
            }
        }
     mAdapter.setList(mList);

    }


}
